package com.liwenfeng.diancanspringboot.mapper;

import com.github.pagehelper.Page;
import com.liwenfeng.diancanspringboot.annotation.AutoFill;
import com.liwenfeng.diancanspringboot.common.enumeration.OperationType;
import com.liwenfeng.diancanspringboot.pojo.dto.EmployeePageQueryDTO;
import com.liwenfeng.diancanspringboot.pojo.entity.Employee;
import org.apache.ibatis.annotations.*;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     */
    @Select("select * from employee where username = #{username} and status!=-1")
    Employee getByUsername(String username);

    /**
     * 新增员工
     */
    @Insert("insert into employee (username, name, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user,job) values (#{username}, #{name}, #{password}, #{phone}, #{sex}, #{idNumber}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser},#{job})")
    @AutoFill(OperationType.INSERT)
    void insert(Employee employee);

    /**
     * 分页查询员工
     */
    Page<Employee> selectByPage(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * 根据id查询员工
     */
    @Select("select * from employee where id = #{id}")
    Employee getById(Long id);

    @AutoFill(OperationType.UPDATE)
    int update(Employee employee);

    @Update("update employee set open_id = #{openId} where id = #{id}")
    int updateOpenId(Long id, String openId);

}
